<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;
use Spatie\Permission\Traits\HasRoles;

//use Illuminate\Database\Eloquent\Model;

class User extends Authenticatable {
	use Notifiable, HasRoles, HasApiTokens;

	/**
	 * The attributes that are mass assignable.
	 *
	 * @var array
	 */
	protected $fillable = [
		'name', 'mobile', 'password',
	];

	/**
	 * The attributes that should be hidden for arrays.
	 *
	 * @var array
	 */
	protected $hidden = [
		'password', 'remember_token',
	];
	public static $rules = [
//        'mobile' => 'required|between:10,15|numeric',
		'mobile' => 'regex:/^[1][0-9]{10}$/',
		'pwd' => 'required',
		"info" => 'required',
//        "from"=>'required'
	];
	public static $message = [
		'mobile.regex' => '手机号格式错误',
		'info.required' => '非法操作',
		'pwd.required' => '密码格式错误',
		'from.required' => '参数错误',
//        'pwd.regex' => '密码格式错误'
	];
	protected function getDateFormat() {
		return time();
	}

	public function findForPassport($username) {

		return User::where('mobile', $username)->first();
	}
}
